package com.connection;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelp extends SQLiteOpenHelper {

	public static final String USER_TABLE = "User";
	public static final String ORDER_TABLE = "List";
	public static final String PRODUCT_TABLE = "Product";

	public static final String database = "Message";
	
	private static final String CREATE_USER = "create table "
			+ USER_TABLE
			+ "(_id integer PRIMARY KEY AUTOINCREMENT, userName TEXT, password TEXT, phone TEXT, address TEXT);";

	private static final String CREATE_ORDER = "create table "
			+ ORDER_TABLE
			+ "(_id integer PRIMARY KEY AUTOINCREMENT, amount TEXT, uname TEXT, pname TEXT, pprice TEXT);";

	private static final String CREATE_PRODUCT = "create table "
			+ PRODUCT_TABLE
			+ "(_id integer PRIMARY KEY AUTOINCREMENT, productName TEXT , price TEXT, picture TEXT, introduction TEXT);";

	public DBHelp(Context c) {
		super(c, database, null, 1);
		
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CREATE_USER);
		db.execSQL(CREATE_ORDER);
		db.execSQL(CREATE_PRODUCT);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS" + USER_TABLE);
		db.execSQL("DROP TABLE IF EXISTS" + ORDER_TABLE);
		db.execSQL("DROP TABLE IF EXISTS" + PRODUCT_TABLE);
		onCreate(db);

	}
}